(defun lilu-slime-connect (host port &optional retry-count sleep-interval client-p)
  (setq retries 0)
  (setq retry-count (or retry-count 10))
  (setq ok nil)
  (while (and (< retries retry-count) (null ok))
    (condition-case error
	(progn
	  (slime-connect host port)
	  (setq ok t))
      (error
       (progn
	 (setq retries (+ retries 1))
	 (message "slime connection failed - retry (%s/%s)" retries retry-count)
	 (sleep-for (or sleep-interval 0.5))))))
  (if (null ok)
      (progn
	(message "slime connection failed - abort")
	(sleep-for 3)
	(if (eql client-p 1)
	    'failed
	  (kill-emacs 1)))
    'ok))

